﻿@model GSOrganization.Application.SysPersonOutput
@{
    Layout = "~/Views/Shared/Create_Layout.cshtml";
}
<style>
    .input-new-tag {
        width: 90px;
    }

        .input-new-tag input {
            height: 100%;
            border: none;
            padding-left: 0px;
        }

    .tag .layui-btn .tag-close:hover {
        border-radius: 2px;
        background-color: #FF5722;
        color: #fff;
    }

    .tag .layui-btn .tag-close {
        margin-left: 8px;
        transition: all .2s;
        -webkit-transition: all .2s;
    }
</style>
<script>
    var parentSelectedType = "多选"; //父界获取此值，来判断是单选还是多选。参考值：多选，单选

    var parentToChildArray = [];
    //子页面调用父页面的方法，传值
    function selectValue(data) {
        debugger
        parentToChildArray = data;
        var content = ""; //需要添加到check显示区域中的内容

        for (var i = 0; i < data.length; i++) {

            content += '<button value="' + data[i].Id + '" type="button" class="tag-item layui-btn layui-btn-primary layui-btn-sm">'
                + data[i].Name + '<i onclick="$(this).parent().remove();" class="layui-icon layui-unselect tag-close">ဆ</i></button>';

        }
         
        $('#checkSysRoleId').append(content);  //为隐藏控件赋值


    }

    function GetValue(obj) {
        console.log(obj);//父界面接收子界面的值
    }
    function showModalMany(me, url, dialogWidth, callback) { //弹出窗体，多选
        if (dialogWidth == null || dialogWidth == "undefined" || dialogWidth == "") {
            dialogWidth = 968;
        }

        parentSelectedType = "多选";

        layer.open({
            title: "可以多选角色",
            type: 2,
            area: [dialogWidth + 'px', '450px'],
            fixed: false, //不固定
            maxmin: true,
            content: url,
            success: function (layero, index) {
                // alert(3)
                //debugger
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(me);
            }
        });


        if (callback != null) {
            callback();
            alert("callback")
        }
    }

</script>
<form class="layui-form" action="" lay-filter="layui">
    <input type="hidden" name="Id" id="Id" value="@Html.DisplayFor(model => model.Id)" />

    <div class="layui-form-item">
        <label class="layui-form-label required">登录用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="LoginName" required lay-verify="required" placeholder="请填写" autocomplete="off" class="layui-input" value="@Html.DisplayFor(model => model.LoginName)" />
        </div>
    </div>
    @if (Model == null || string.IsNullOrWhiteSpace(Model.Id))
    {
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="Password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="SurePassword" required lay-verify="required" placeholder="请再次输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>  <div class="layui-inline">
                <div class="layui-form-mid layui-word-aux">
                    <p>1.密码长度为8-16位之间</p>
                    <p>2.必须包含数字、大小写字母</p>
                    <p>3.键盘上连续字符不能超过3位</p>
                    <p>4.连续或重复字母不能大于等于3位</p>
                    <p>5.连续或重复数字不能大于等于3位</p>
                </div>
            </div>
        </div>
    }
    <div class="layui-form-item">
        <label class="layui-form-label">单位名称</label>
        <div class="layui-input-inline">
            <input type="text" name="DepartmentName" placeholder="单位名称" class="layui-input" value="@Html.DisplayFor(model => model.DepartmentName)" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">社会信用统一代码</label>
        <div class="layui-input-inline">
            <input type="text" name="Code"placeholder="社会信用统一代码"class="layui-input" value="@Html.DisplayFor(model => model.Code)" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位地址</label>
        <div class="layui-input-inline">
            <input type="text" name="Address" placeholder="单位地址" class="layui-input" value="@Html.DisplayFor(model => model.Address)" />
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">法人</label>
        <div class="layui-input-inline">
            <input type="text" name="Representative" placeholder="法人" class="layui-input" value="@Html.DisplayFor(model => model.Representative)" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-inline">
            <input type="text" name="ContactPerson" placeholder="联系人" class="layui-input" value="@Html.DisplayFor(model => model.ContactPerson)" />
        </div>
    </div>
  
    <div class="layui-form-item">
        <label class="layui-form-label required">电话</label>
        <div class="layui-input-inline">
            <input type="text" name="ContactPhone" lay-verify="required" placeholder="请填写联系人电话" autocomplete="off" class="layui-input" value="@Html.DisplayFor(model => model.ContactPhone)" />
        </div>
    </div>

    <div class="layui-form-item">


        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <a class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" onclick="showModalMany('SysRoleId','../../SysRole');">
                选择
            </a>

            <div id="checkSysRoleId">
                @if (Model != null && Model.SysRole != null)
                {
                    @foreach (var item in Model.SysRole)
                    {
                        <button value="@item.Id" type="button" class="tag-item layui-btn layui-btn-primary layui-btn-sm">
                            @item.Name <i onclick="$(this).parent().remove();" class="layui-icon layui-unselect tag-close">ဆ</i>
                        </button>

                    }

                }
            </div>


        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">

            <input type="radio" name="State" value="开启" title="开启" @((Model == null || (!string.IsNullOrWhiteSpace(Model.State) && Model.State == "开启")) ? "checked" : "") />
            <input type="radio" name="State" value="关闭" title="关闭" @((Model != null && !string.IsNullOrWhiteSpace(Model.State) && Model.State == "关闭") ? "checked" : "") />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block" style="width:332px;">
            <textarea name="Remark" placeholder="请输入内容" class="layui-textarea">@Html.DisplayFor(model => model.Remark)</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">

            <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-submit lay-filter="formsubmit" id="submit">提交</button>

            <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="return window.location.href='../SysPerson'">返回</a>


        </div>
    </div>
</form>

<script>

    layui.use(function () {
        var $ = layui.jquery,
            table = layui.table,
            form = layui.form,
            GSLayui = layui.GSLayui;
    

        //监听提交
        form.on('submit(formsubmit)', function (data) {
            var entity = data.field;


            var SysRoles = [];
            $('#checkSysRoleId').children().each(function (index, domEle) {
                var item = $(this).val();
                SysRoles.push({ Id: item });
            });

            entity.SysRoles = SysRoles;


            var data = ajaxPost("/SysPerson/EditSysPerson", entity);

            if (data.code == 200) {
                layer.alert(data.msg, {
                    title: "成功"
                });
                setTimeout(function () {
                    return window.location.href = '/SysPerson'
                }, 2000);

            } else {
                layer.alert(data.msg, {
                    title: "失败"
                });
            }

            return false;
        });
    });


</script> 